import React,{Component} from 'react'

import {
    View,
    Text,
    FlatList,
    StyleSheet,
    ScrollView,
    TouchableNativeFeedback
}from 'react-native'


const styles=StyleSheet.create({
    warp:{
        width:'100%',
    },
    addtop:{
        width:'100%',
        height:50,
        borderRadius:5,
        backgroundColor:'rgb(255,97,3)',
        flexDirection:'row',
        justifyContent:'center',
        alignItems:'center'
    },
    content:{
        width:'100%',

    },
    list:{
        width:'100%',
        height:50,
        flexDirection:'row',
        backgroundColor:'white',
        justifyContent:'space-around',
        alignItems:'center'
    },
    listleft:{
        width:'80%',
        height:'100%',
        flexDirection:'row',
        justifyContent:'center',
        alignItems:'center'
    },
    jiange:{
        width:'100%',
        borderTopWidth:1,
        borderColor:'rgba(150,150,150,0.2)',
        height:1
    },
    listright:{
        width:'20%',
        height:'100%',
        borderLeftWidth:1,
        borderColor:'rgba(150,150,150,0.2)',
        flexDirection:'row',
        justifyContent:'center',
        alignItems:'center'
    }
})


export default class FoodType extends Component{
    static navigationOptions={
        title:'菜类管理',
        headerTitleStyle: {
        alignSelf:'center'
      },
    };

    state={
        datesource:[1,2,3],
        typedata:[]
    }

    getallfoodtype=async function(){
        
        try {
            let response = await fetch(global.mainurl+"bossHelper/getFoodType?sellerid="+global.sellerid+"&userid="+global.userdata.id+"&token="+global.token);
            var data=await response.json()
            console.log(data)
            if(data.code==1){
                this.setState({
                    typedata:data.data
                })
            }
            else{
					ToastAndroid.show(data.msg, ToastAndroid.SHORT);			
						}
            } 
    catch(error) {
      console.log(error)
            ToastAndroid.show('网络出错', ToastAndroid.SHORT);
            }
    }

    componentWillMount(){
        this.getallfoodtype()
    }


    render(){
        return(
            <View style={styles.warp}>
            <TouchableNativeFeedback
            onPress={()=>{this.props.navigation.navigate("FoodTypeAdd",{reload:()=>{this.getallfoodtype()}})}}
            >
            <View style={styles.addtop}>
            <Text style={{color:'white',}}>
            添加菜品类别
            </Text>
            </View>
            </TouchableNativeFeedback>
            <View style={{height:'100%',paddingBottom:100}}>
            <FlatList
                style={styles.content}
                keyExtractor={(item, index) => index}
                ItemSeparatorComponent={()=>{
                return(
                    <View style={styles.jiange}/>
                    )
                
                }}
                data={this.state.typedata}
                renderItem={
                    (item)=>{
                        return(
                            <View style={styles.list}>
                            <TouchableNativeFeedback>
                            <View style={styles.listleft}>
                            <Text>
                            {item.item.name}
                            </Text>
                            </View>
                            </TouchableNativeFeedback>
                            

                            </View>
                        )
                    }
                }
            />
            </View>

            </View>
        )
    }
}


